$(function () {
    let form = layui.form;
    form.verify({
        pwd: [
            /^[\S]{6,12}$/,
            "密码必须6-12位"
        ],
        newPwd: function (value) {
            let v1 = $("[name=oldPwd]").val();
            if (value == v1) {
                return '新密码不能与旧密码相同'
            }
        },
        rePwd: function (value) {
            let v2 = $("[name=rePwd]").val();
            if (value !== v2) {
                return "两次密码不一致"
            }
        }
    })

    $("#formpwd").on("submit", function (e) {
        e.preventDefault();
        axios({
            method: "POST",
            url: "/my/updatepwd",
            data: $(this).serialize()
        }).then(res => {
            console.log(res);
            if (res.data.status !== 0) {
                return layui.layer.msg(res.data.message)
            }
            layui.layer.msg("修改成功")
            $("#formpwd")[0].reset();
            setTimeout(() => {
                window.parent.location.href = '/login.html'
            },2000)
        })
    })
})